package com.example.ui.contact.bean;

import java.io.Serializable;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class User implements Serializable {
	/**
	 *用户相关信息
	 */
	private static final long serialVersionUID = 1L;
	private String UserId;
	private String nick;
	private int headIcon;

	private String sortKey="A";
	private String telNum ="10086";
	private String distatce;
	public String getDistatce() {
		return distatce;
	}
	public void setDistatce(String distatce) {
		this.distatce = distatce;
	}


	/**
	 * 推送消息相关信息
	 */
	private int msg_type = 0;  //记录消息类型变量
	private int msg_total =0;  //记录消息数目变量
	public static int notify_msg_num = 1;  //系统通知
	public static int me_msg_num = 2;      //提到我的
	public static int comment_msg_num = 3; //评论
	public static int funs_msg_num = 4;	   //赞
	public static int chat_msg_num = 5;    //私信消息
	public static int request_msg_num = 6; //好友请求
	
	private String id;  //用户注册时的id
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public User(String UserId, String telNum, String nick) {
		this.UserId = UserId;
		this.telNum = telNum;
		this.nick = nick;
		
		//String str = getFirstSpell(nick);
		sortKey = getFirstSpell(nick).substring(0, 1).toUpperCase();
	}
    public User(){
    	
    }
	public int getMsgTotal(){
		return msg_total;
	}
    public void setMsgTotal(){
    	msg_total = notify_msg_num+me_msg_num+comment_msg_num
    			+funs_msg_num+chat_msg_num+request_msg_num;
    }
    
    public int getMsgNotifyNum(){
    	return notify_msg_num;
    }
    public void setMsgNotifyNum(){
    	notify_msg_num++;
    }
    
	public String getUserId() {
		return UserId;
	}

	public void setUserId(String userId) {
		UserId = userId;
	}


	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public int getHeadIcon() {
		return headIcon;
	}

	public void setHeadIcon(int headIcon) {
		this.headIcon = headIcon;
	}

	public void setSortKey(String sortKey){
		this.sortKey = sortKey;
	}
	public String getSortKey(){
		return sortKey;
	}

	public String getTelNum() {
		return telNum;
	}

	public void setTelNum(String telNum) {
		this.telNum = telNum;
	}
	@Override
	public String toString() {
		return "User [UserId=" + UserId 
				+ ", nick=" + nick + ", headIcon=" + headIcon;
	}
	
	
    /**  
     * 获取汉字串拼音首字母，英文字符不变  
     * @param chinese 汉字串  
     * @return 汉语拼音首字母  
     */   
    public static String getFirstSpell(String chinese) {   
            StringBuffer pybf = new StringBuffer();   
            char[] arr = chinese.toCharArray();   
            HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();   
            defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);   
            defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);   
            for (int i = 0; i < arr.length; i++) {   
                    if (arr[i] > 128) {   
                            try {   
                                    String[] temp = PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat);   
                                    if (temp != null) {   
                                            pybf.append(temp[0].charAt(0));   
                                    }   
                            } catch (BadHanyuPinyinOutputFormatCombination e) {   
                                    e.printStackTrace();   
                            }   
                    } else {   
                            pybf.append(arr[i]);   
                    }   
            }   
            return pybf.toString().replaceAll("\\W", "").trim();   
    }
}
